/**********************************************************
 * SearchListCriteria.java.java 
 * Created by Ashutosh
 * Last modified Date: Sep 18, 2008 11:07:37 AM by Ashutosh
 * Revision: <svn revision #> 
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 **********************************************************/

package com.printeverywhere.util;

import org.apache.log4j.Logger;
import java.util.HashMap;
import java.util.Set;

/**
 * The Class SearchListCriteria Utility for building Listcriteria in hibernate.
 * 
 * @author Jigar Mistry
 */
public class SearchListCriteria {
	
	/** Logger for this class. */
	private static final Logger logger = Logger.getLogger(SearchListCriteria.class);

	/** The Constant EQ. */
	public static final String EQ = "eq";

	/** The Constant GE. */
	public static final String GE = "ge";

	/** The Constant GT. */
	public static final String GT = "gt";

	/** The Constant ILIKE. */
	public static final String ILIKE = "ilike";

	/** The Constant ISNULL. */
	public static final String ISNULL = "isNull";

	/** The Constant ISNOTNULL. */
	public static final String ISNOTNULL = "isNotNull";

	/** The Constant LE. */
	public static final String LE = "le";

	/** The Constant LIKE. */
	public static final String LIKE = "like";

	/** The Constant LT. */
	public static final String LT = "lt";

	/** The Constant NE. */
	public static final String NE = "ne";

	/** The Constant IN. */
	public static final String IN = "in";

	/** The attributes. */
	private HashMap<String, Object[]> attributes = new HashMap<String, Object[]>();

	/** The order by. */
	private String orderBy = null;

	/** The asc. */
	private boolean asc;

	/**
	 * Gets the attribute.
	 * 
	 * @param key the key
	 * 
	 * @return the attribute
	 */
	public Object[] getAttribute(String key) {
		if (logger.isDebugEnabled()) {
			logger.debug("getAttribute(String) - start"); //$NON-NLS-1$
		}

		Object[] returnObjectArray = attributes.get(key);
		if (logger.isDebugEnabled()) {
			logger.debug("getAttribute(String) - end"); //$NON-NLS-1$
		}
		return returnObjectArray;
	}

	/**
	 * Gets the attribute names.
	 * 
	 * @return the attribute names
	 */
	public Set<String> getAttributeNames() {
		if (logger.isDebugEnabled()) {
			logger.debug("getAttributeNames() - start"); //$NON-NLS-1$
		}

		Set<String> returnSet = attributes.keySet();
		if (logger.isDebugEnabled()) {
			logger.debug("getAttributeNames() - end"); //$NON-NLS-1$
		}
		return returnSet;
	}

	/**
	 * Gets the order by.
	 * 
	 * @return the orderBy
	 */
	public String getOrderBy() {
		return orderBy;
	}

	/**
	 * Checks if is asc.
	 * 
	 * @return the asc
	 */
	public boolean isAsc() {
		return asc;
	}

	/**
	 * Removes the all attribute.
	 */
	public void removeAllAttribute() {
		if (logger.isDebugEnabled()) {
			logger.debug("removeAllAttribute() - start"); //$NON-NLS-1$
		}

		attributes.clear();

		if (logger.isDebugEnabled()) {
			logger.debug("removeAllAttribute() - end"); //$NON-NLS-1$
		}
	}

	/**
	 * Removes the attribute.
	 * 
	 * @param key the key
	 * 
	 * @return the object
	 */
	public Object removeAttribute(String key) {
		if (logger.isDebugEnabled()) {
			logger.debug("removeAttribute(String) - start"); //$NON-NLS-1$
		}

		Object returnObject = attributes.remove(key);
		if (logger.isDebugEnabled()) {
			logger.debug("removeAttribute(String) - end"); //$NON-NLS-1$
		}
		return returnObject;
	}

	/**
	 * Sets the asc.
	 * 
	 * @param asc the asc to set
	 */
	public void setAsc(boolean asc) {
		this.asc = asc;
	}

	/**
	 * Sets the attribute.
	 * 
	 * @param key the key
	 * @param value the value
	 */
	public void setAttribute(String key, Object value[]) {
		if (logger.isDebugEnabled()) {
			logger.debug("setAttribute(String, Object[]) - start"); //$NON-NLS-1$
		}

		attributes.put(key, value);

		if (logger.isDebugEnabled()) {
			logger.debug("setAttribute(String, Object[]) - end"); //$NON-NLS-1$
		}
	}

	/**
	 * Sets the order by.
	 * 
	 * @param orderBy the orderBy to set
	 */
	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}
}